package de.jmda.gen.java.impl;

import java.util.ArrayList;
import java.util.List;

import de.jmda.gen.Generator;
import de.jmda.gen.impl.AbstractCompoundGenerator;
import de.jmda.gen.java.DeclaredTypeGenerator;
import de.jmda.gen.java.DeclaredTypesGenerator;

/**
 * Maintains a list of {@link DeclaredTypeGenerator}s.
 *
 * @author rwegner
 */
public class DefaultDeclaredTypesGenerator
		extends AbstractCompoundGenerator
		implements DeclaredTypesGenerator
{
	private List<DeclaredTypeGenerator> declaredTypeGenerators;

	public DefaultDeclaredTypesGenerator()
  {
	  super();
	  setComponentSeparator(DOUBLE_LINE_SEPARATOR);
  }

	/**
	 * Aggregates and returns the results of
	 * <ul>
	 *   <li>{@link #getDeclaredTypeGenerators()}</li>
	 * </ul>
	 * in the order listed above.
	 * 
	 * @see de.jmda.gen.CompoundGenerator#getGeneratorComponents()
	 */
	@Override
  public List<Generator> getGeneratorComponents()
  {
		// copy specific generators to non-specific generators and make Java happy
		List<Generator> result = new ArrayList<Generator>();
		
		result.addAll(getDeclaredTypeGenerators());

		return result;
  }

	/**
	 * @see de.jmda.gen.java.DeclaredTypesGenerator#getDeclaredTypeGenerators()
	 */
	@Override
  public List<DeclaredTypeGenerator> getDeclaredTypeGenerators()
  {
		if (declaredTypeGenerators == null)
		{
			declaredTypeGenerators = new ArrayList<DeclaredTypeGenerator>();
		}
		
		return declaredTypeGenerators;
  }

	public void setDeclaredTypeGenerators(
      List<DeclaredTypeGenerator> declaredTypeGenerators)
  {
		if (declaredTypeGenerators == null)
		{
			return;
		}

  	this.declaredTypeGenerators = declaredTypeGenerators;
  }

	/**
	 * Convenience method to add an <code>DeclaredTypeGenerator</code> to
	 * {@link #getDeclaredTypeGenerators()}.
	 *
	 * @param declaredTypeGenerator
	 */
	public void add(DeclaredTypeGenerator declaredTypeGenerator)
	{
		getDeclaredTypeGenerators().add(declaredTypeGenerator);
	}
}